Skip to content

(GH-1761) Fix locale-dependent prefetch failure in mysql_database provider - #1769

Open
jst-cyr wants to merge 3 commits into
mainfrom
jstcyr/fix-mysql-database-locale-prefetch-1761
Open

jst-cyr wants to merge 3 commits into
mainfrom
jstcyr/fix-mysql-database-locale-prefetch-1761

Conversation

@jst-cyr

@jst-cyr jst-cyr commented Nov 10, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #1761.

mysql_database's self.instances rescues a missing database during prefetch by checking whether the mysql/mariadb client's error message contains the English string "Unknown database". When the server/client reports errors in another locale (the reporter saw this on RHEL 9 with MariaDB 11.4 under a German locale, which prints "Unbekannte Datenbank"), that string match fails, the exception is re-raised, and prefetch fails for every mysql_database resource in the catalog — not just the missing one.

This is especially easy to hit via mysql::server::account_security, which declares:

mysql_database { 'test':
  ensure  => 'absent',
  require => Anchor['mysql::server::end'],
}

The first run removes the test database as desired. Every run after that fails during prefetch, because the database is now legitimately absent and the client raises ERROR 1049 (42000): Unbekannte Datenbank 'test' (or the equivalent in whatever locale the DB is configured for), which the old check didn't recognize.

Fix

Match on the numeric MySQL/MariaDB error code 1049 (ER_BAD_DB_ERROR) instead of the localized message text, since the code is stable across locales while the message text is not.

Test plan

  • Added a unit test reproducing the German-locale error string from the issue (ERROR 1049 (42000): Unbekannte Datenbank 'managed_missing') and confirming it's now handled the same as the English-locale case.
  • Existing spec/unit/puppet/provider/mysql_database/mysql_spec.rb suite passes (17 examples, 0 failures).

jst-cyr and others added 3 commits November 9, 2026 21:25
The mysql_database provider's self.instances rescued a missing
database by matching the English string "Unknown database" in the
error message from the mysql/mariadb client. Under a non-English
server/client locale (e.g. German, which reports "Unbekannte
Datenbank"), that match fails and the exception is re-raised,
breaking prefetch for every mysql_database resource in the catalog.

This surfaced via mysql::server::account_security, which declares
`mysql_database { 'test': ensure => absent }`: once the database is
removed on a first run, every subsequent run fails during prefetch
under a non-English locale.

Match on the numeric, locale-independent MySQL/MariaDB error code
1049 (ER_BAD_DB_ERROR) instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Use String#include? instead of a regex match with a literal-only
pattern, per CI's RuboCop configuration.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jst-cyr
jst-cyr marked this pull request as ready for review November 10, 2026 12:51
@jst-cyr
jst-cyr requested review from a team, alexjfisher and bastelfreak as code owners November 10, 2026 12:51
@jst-cyr

jst-cyr commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

✅ Acceptance Test Results: https://github.com/puppetlabs/puppetlabs-mysql/actions/runs/42744772141?pr=1769

Green across the board, good for review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Puppet fails when test db is not present.

1 participant